function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function r(e, r) {
    return "string" == typeof e ? e + (e.includes("?") ? "&" : "?") + r : "";
}

function t(e) {
    return a.default.getTokens().then(function(t) {
        return n({}, e, {
            url: r(e.url, "accesstoken=" + t.accesstoken)
        });
    });
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var n = Object.assign || function(e) {
    for (var r = 1; r < arguments.length; r++) {
        var t = arguments[r];
        for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
    }
    return e;
};

exports.requestSignature = function(e) {
    var t = e.url, s = e.method, a = e.data, c = e.params, i = "get" === s ? a : c, f = u.default.parseUrl(t).query;
    return e.url = r(t, (0, o.generateSignParamsStr)(n({}, f, i))), Promise.resolve(e);
}, exports.requestAccesstoken = t, exports.requestOpenId = function(e) {
    return a.default.getTokens().then(function(r) {
        return n({}, e, {
            data: Object.assign({}, e.data, {
                openid: r.openid
            })
        });
    });
}, exports.requestAccesstokenIfExist = function(e) {
    return t(e).catch(function(r) {
        return e;
    });
}, exports.requestEncodeFields = function(e) {
    if (e.formData) {
        var r = Object.keys(e.formData);
        r && r.length && (e.formData = n({}, e.formData), r.forEach(function(r) {
            e.formData[r] = encodeURIComponent(e.formData[r]);
        }), e.formData.encode = 1);
    }
    return Promise.resolve(e);
}, exports.requestUseUploadIfNeccesary = function(e) {
    return e.name && e.filePath && (e.method = "UPLOAD"), Promise.resolve(e);
}, exports.responseResolveOnlySuccess = function(e) {
    return e.code === s.default.SUCCESS ? Promise.resolve(e) : (u.default.qAlert(e.message || "网络错误，请重新尝试!", "操作失败"), 
    Promise.reject(e));
};

var o = require("./api-signature"), s = e(require("./api-code")), u = e(require("./util")), a = e(require("./user"));